<?php
class sfWidgetFormSchemaFormatterDiv extends sfWidgetFormSchemaFormatter
{
 protected
	 $rowFormat              = "<div class=\"form_row%row_class%\" id=\"%row_id%\">
											        %error%
					                    <div class=\"form-row-label\">%label% \n <div class=\"form-row-field\">%field%</div></div>
					                    %help% %hidden_fields%\n</div>\n",
	 $errorRowFormat         = "<div class=\"error\">%errors%</div>",
	 $errorListFormatInARow  = "  <div class=\"error\">\n%errors%</div>\n",
	 $errorRowFormatInARow   = "  %error%\n",
	 $helpFormat             = '<div class="form_help">%help%</div>',
	 $decoratorFormat        = "<div>\n  %content%</div>";

 
  public function formatRow($label, $field, $errors = array(), $help = '', $hiddenFields = null)
  {
		
   $row = parent::formatRow(
      $label,
      $field,
      $errors,
      $help,
      $hiddenFields
    );
    preg_match_all("#for=\"(.*?)\">#s", $label, $matches, PREG_PATTERN_ORDER);
    
    
    return strtr($row, array(
      '%row_class%' => (count($errors) > 0) ? ' _error' : '',
      '%row_id%' => 'row_' . $matches[1][0],
    ));

  }
	
	public function generateLabel($name, $attributes = array())
  {
    
		$labelName = $this->generateLabelName($name);

    if (false === $labelName)
    {
      return '';
    }

    if (!isset($attributes['for']))
    {
      $attributes['for'] = $this->widgetSchema->generateId($this->widgetSchema->generateName($name));
    }
		//echo $labelName;
    return $this->widgetSchema->renderContentTag('label', $labelName, $attributes);
  }
	
}